<?php

class Inquiry extends Controller
{
	var $data=array();
	
	public function __construct()
	{
		parent::Controller();

		$this->data['warning']="";
		$this->data['f_name']="";
		$this->data['l_name']="";
		$this->data['addr']="";
		$this->data['city']="";
		$this->data['prov']="";
		$this->data['p_code']="";
		$this->data['email']="";
		$this->data['p_number']="";
		$this->data['alt_p_number']="";
		$this->data['description']="";
		
		$this->data['builtincab']="builtincab";
		$this->data['brief_description']="";
		$this->data['bathroom2piece']="";
		$this->data['bathroom3piece']="";
		$this->data['gasfireplace']="";
		$this->data['pubstylebar']="";
		$this->data['walkupbarconvenience']="";
		$this->data['office']="";
		$this->data['recreationarea']="";
		$this->data['bedrooms']="";
		$this->data['homegym']="";
		$this->data['finishedlaundryroom']="";
		$this->data['kitchen']="";
		$this->data['enlargewindow']="";
		$this->data['newextentrance']="";
		$this->data['inlawapt']="";
		$this->data['carpetberber']="";
		$this->data['ceramictile']="";
		$this->data['laminate']="";
		$this->data['enghdwood']="";

		// load 'url' helper
		$this->load->helper('url');

		// load 'form' helper
		$this->load->helper('form');

		// load 'validation' class
		$this->load->library('validation');

		// load 'email' class
		$this->load->library('email');

	}
	
	function index()
	{	
		if($this->input->post('submit'))
		{
			$this->data['f_name']=trim($this->input->post('first_name'));
			$this->data['l_name']=trim($this->input->post('last_name'));
			$this->data['addr']=trim($this->input->post('address'));
			$this->data['city']=trim($this->input->post('city'));
			$this->data['prov']=trim($this->input->post('province'));
			$this->data['p_code']=trim($this->input->post('postal_code'));
			$this->data['email']=trim($this->input->post('email'));
			$this->data['p_number']=trim($this->input->post('phone_number'));
			$this->data['alt_p_number']=trim($this->input->post('alt_phone_number'));
			$this->data['description']=trim($this->input->post('description'));

			if(strcmp("", $this->data['f_name'])==0)	
			{
				$this->data['warning']="* First name was not entered. <br>";
			}
/*
			else if(strcmp("", $this->data['addr'])==0)
			{
				echo "Address was not entered. ";
			}
			else if(strcmp("", $this->data['city'])==0)
			{
				echo "City name was not entered. ";
			}
			else if(strcmp("", $this->data['prov'])==0)
			{
				echo "Province name was not entered. ";
			}
			else if(strcmp("", $this->data['p_code'])==0)
			{
				echo "Postal Code was not entered. ";
			}
*/
			if(strcmp("", $this->data['description'])!=0 && strcmp("", $this->data['p_number'])!=0 && strcmp("", $this->data['email'])!=0 && strcmp("", $this->data['f_name'])!=0)
			{
				$this->data['warning']="Your request has been sent!";
				$this->email();
				$this->reset();
			}
			else if(strcmp("", $this->data['f_name'])==0)
			{
				$this->data['warning']=$this->data['warning']."* Name was not entered. <br>";
			}
			else if(strcmp("", $this->data['email'])==0)
			{
				$this->data['warning']=$this->data['warning']."* Email was not entered. <br>";
			}
			else if(strcmp("", $this->data['p_number'])==0)
			{
				$this->data['warning']=$this->data['warning']."* Primary contact number was not entered. <br>";
			}
			else if(strcmp("", $this->data['description'])==0)
			{
				$this->data['warning']=$this->data['warning']."* Please enter the description. <br/>";
			}
			else
			{
				echo "You may have missed some information!".'<br />';
			}
		}
		else if($this->input->post('reset'))
		{
			$this->reset();
		}

		$this->load->view("inquiry",$this->data);
	}
	
	function reset()
	{
		$this->data['f_name']="";
		$this->data['l_name']="";
		$this->data['addr']="";
		$this->data['city']="";
		$this->data['prov']="";
		$this->data['p_code']="";
		$this->data['email']="";
		$this->data['p_number']="";
		$this->data['alt_p_number']="";
		$this->data['description']="";
		$this->data['builtincab']="";
		$this->data['brief_description']="";
		$this->data['bathroom2piece']="";
		$this->data['bathroom3piece']="";
		$this->data['gasfireplace']="";
		$this->data['pubstylebar']="";
		$this->data['walkupbarconvenience']="";
		$this->data['office']="";
		$this->data['recreationarea']="";
		$this->data['bedrooms']="";
		$this->data['homegym']="";
		$this->data['finishedlaundryroom']="";
		$this->data['kitchen']="";
		$this->data['enlargewindow']="";
		$this->data['newextentrance']="";
		$this->data['inlawapt']="";
		$this->data['carpetberber']="";
		$this->data['ceramictile']="";
		$this->data['laminate']="";
		$this->data['enghdwood']="";
	}
	
	function email()
	{
		$msg="";

		$this->load->library('email');

		$this->email->from($this->data['email'], $this->data['f_name']);
		$this->email->to('rycyk@shaw.ca');
		$this->email->cc('has_9@hotmail.com');
//		$this->email->bcc('has9live@yahoo.com');

		$this->email->subject('Inquiry/Quote from Unlimited Builders, Website');

		$msg=$msg."Address     : ".$this->data['addr']."\n";
		$msg=$msg."City        : ".$this->data['city']."\n";
		$msg=$msg."Province    : ".$this->data['prov']."\n";
		$msg=$msg."Postal Code : ".$this->data['p_code']."\n";
		$msg=$msg."Email       : ".$this->data['email']."\n";
		$msg=$msg."Phone #     : ".$this->data['p_number']."\n";
		$msg=$msg."Alt Phone # : ".$this->data['alt_p_number']."\n";
		$msg=$msg."Description : ".$this->data['description']."\n\n\n";
		$msg=$msg."Flooring : \n\n";

		if(isset($_POST['builtincab']) && $_POST['builtincab'] == 'Yes') 
		{
			$msg=$msg."  Built-in Cabinet\n";
		}
		if(isset($_POST['bathroom2piece']) && $_POST['bathroom2piece'] == 'Yes') 
		{
			$msg=$msg."  2 piece Bathroom\n";
		}
		if(isset($_POST['bathroom3piece']) && $_POST['bathroom3piece'] == 'Yes') 
		{
			$msg=$msg."  2 piece Bathroom\n";
		}
		if(isset($_POST['gasfireplace']) && $_POST['gasfireplace'] == 'Yes') 
		{
			$msg=$msg."  Gas Fireplace\n";
		}
		if(isset($_POST['pubstylebar']) && $_POST['pubstylebar'] == 'Yes') 
		{
			$msg=$msg."  Pub Style sit at Bar\n";
		}
		if(isset($_POST['walkupbarconvenience']) && $_POST['walkupbarconvenience'] == 'Yes') 
		{
			$msg=$msg."  Walk-up bar/Convenience centre\n";
		}
		if(isset($_POST['office']) && $_POST['office'] == 'Yes') 
		{
			$msg=$msg."  Office\n";
		}
		if(isset($_POST['recreationarea']) && $_POST['recreationarea'] == 'Yes') 
		{
			$msg=$msg."  Recreation Area\n";
		}
		if(isset($_POST['bedrooms']) && $_POST['bedrooms'] == 'Yes') 
		{
			$msg=$msg."  Bedrooms\n";
		}
		if(isset($_POST['homegym']) && $_POST['homegym'] == 'Yes') 
		{
			$msg=$msg."  Home Gym\n";
		}
		if(isset($_POST['finishedlaundryroom']) && $_POST['finishedlaundryroom'] == 'Yes') 
		{
			$msg=$msg."  Finished Laundry Room\n";
		}
		if(isset($_POST['kitchen']) && $_POST['kitchen'] == 'Yes') 
		{
			$msg=$msg."  Kitchen\n";
		}
		if(isset($_POST['enlargewindow']) && $_POST['enlargewindow'] == 'Yes') 
		{
			$msg=$msg."  Enlarge Window\n";
		}
		if(isset($_POST['newextentrance']) && $_POST['newextentrance'] == 'Yes') 
		{
			$msg=$msg."  New Exterior Entrance\n";
		}
		if(isset($_POST['inlawapt']) && $_POST['inlawapt'] == 'Yes') 
		{
			$msg=$msg."  In-Law Apartment\n";
		}
		if(isset($_POST['carpetberber']) && $_POST['carpetberber'] == 'Yes') 
		{
			$msg=$msg." Carpet / Berber\n";
		}
		if(isset($_POST['ceramictile']) && $_POST['ceramictile'] == 'Yes') 
		{
			$msg=$msg."  Ceramic Tile\n";
		}
		if(isset($_POST['laminate']) && $_POST['laminate'] == 'Yes') 
		{
			$msg=$msg."  Laminate\n";
		}
		if(isset($_POST['enghdwood']) && $_POST['enghdwood'] == 'Yes') 
		{
			$msg=$msg."  Engineered Hardwood";
		}

		$this->email->message($msg);
		$this->email->send();

//		echo $this->email->print_debugger();
	}
}
?>